const Router = require('koa-router');

const router = new Router({ prefix: '/address' });

const { auth } = require('../middleware/auth.middleware.js');
const { validator } = require('../middleware/addr.middleware.js');
const { create, findAll, update, remove, setDefault } = require('../controller/addr.controller.js');


router.post('/', auth, validator({
    consignee: { type: 'string', required: true },
    phone: { type: 'string', format: /^1\d{10}$/, required: true },
    address: { type: 'string', required: true },
}), create)

// 获取地址列表
router.get('/', auth, findAll)

// 更新地址
router.put('/:id', auth, validator({
    consignee: { type: 'string', required: true },
    phone: { type: 'string', format: /^1\d{10}$/, required: true },
    address: { type: 'string', required: true },
}), update)

// 删除地址
router.delete('/:id', auth, remove)

// 设置默认地址
router.patch('/:id', auth, setDefault)

module.exports = router;